//
//  AppDelegate.m
//  DualMediation
//
//  Created by YeJary on 2025/6/23.
//

#import "AppDelegate.h"
#import "ViewController.h"
#import <DualMediationSDK/DualMediationSDKPublic.h>
@interface AppDelegate ()

@property (nonatomic, assign) BOOL isColdLaunch;

@end

ViewController * _viewController;

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    
    self.isColdLaunch = YES;

    CGRect bounds = [[UIScreen mainScreen] bounds];
    self.window = [[UIWindow alloc] initWithFrame: bounds];

    _viewController = [[ViewController alloc]init];
    
    // Modern iOS layout configuration
    if (@available(iOS 11.0, *)) {
        // iOS 11+ uses safe area layout guides automatically
    } else {
        _viewController.automaticallyAdjustsScrollViewInsets = NO;
        _viewController.extendedLayoutIncludesOpaqueBars = NO;
        _viewController.edgesForExtendedLayout = UIRectEdgeAll;
    }
    
    [self.window setRootViewController:_viewController];
    [self.window makeKeyAndVisible];
    
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidFinishLaunching:application withOptions:launchOptions];
    
    return YES;
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Application lifecycle handling can be implemented here if needed
    
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidBecomeActive:application];
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Application lifecycle handling can be implemented here if needed
    
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationWillResignActive:application];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Application lifecycle handling can be implemented here if needed
    
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidEnterBackground:application];
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Application lifecycle handling can be implemented here if needed
    
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationWillEnterForeground:application];
}

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options {
    // URL handling can be implemented here if needed
    
    // 调用SDK生命周期方法
    BOOL sdkHandled = [[DualMediationSDKPublic sharedInstance] applicationOpenURL:app url:url options:options];
    
    return sdkHandled || YES;
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationWillTerminate:application];
}

- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidReceiveMemoryWarning:application];
}

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidReceiveRemoteNotification:application userInfo:userInfo];
}

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
    // 调用SDK生命周期方法
    [[DualMediationSDKPublic sharedInstance] applicationDidReceiveLocalNotification:application notification:notification];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void(^)(NSArray<id<UIUserActivityRestoring>> * _Nullable restorableObjects))restorationHandler {
    // 调用SDK生命周期方法
    return [[DualMediationSDKPublic sharedInstance] applicationContinueUserActivity:application userActivity:userActivity restorationHandler:restorationHandler];
}

@end
